//
// Created by yunnan xu on 2021/6/12.
//

#ifndef ANDROIDGRAPHICSDEMOS_RENDERITEMOPAQUE_H
#define ANDROIDGRAPHICSDEMOS_RENDERITEMOPAQUE_H
#include "RenderItem.h"
#include <memory>
#include <vector>
#include <gles3/gl32.h>
#include <glm.hpp>
#include "VertexAttrib.h"
#include "GLESUtils.h"

class Buffer;
class Texture;
class Model;

template<GraphicsAPI api> class RenderItemOpaque;

template<>
class RenderItemOpaque<GraphicsAPI::GLESv3> : public IRenderItem{
public:

    RenderItemOpaque();
    virtual ~ RenderItemOpaque() = default;

    void LoadDummyData(
            DummyItemType dummy_type,
            glm::vec3 translation = glm::vec3(0, 0, 0),
            glm::vec3 rotation = glm::vec3(0, 0, 0),
            glm::vec3 scale = glm::vec3(1.0, 1.0, 1.0),
            bool with_rb=false);

    virtual void LoadMeshFileData(const char * mesh_file,
                                  glm::vec3 translation = glm::vec3(0, 0, 0),
                                  glm::vec3 rotation = glm::vec3(0, 0, 0),
                                  glm::vec3 scale = glm::vec3(1.0, 1.0, 1.0)) = 0;

    GLuint GetVAO() const {return vertexArrayObject;}


protected:
    std::vector<std::pair<VertexAttribType, std::shared_ptr<Buffer>>> vertexAttribBufferList; // 顶点属性 buffer 列表
    std::shared_ptr<Buffer> vertexIndexBuffer;    // 顶点index buffer
    int vertexNumber{};
    int faceNumber{};
    bool with_skinned_mesh_anim;

    void AppendVertexAttribData(VertexAttribType attrib_type, const void * data, uint size, uint strip, uint offset);
    void SetElementData(const void * element_data, size_t element_data_length);
    GLuint vertexArrayObject{};
};

#endif //ANDROIDGRAPHICSDEMOS_RENDERITEMOPAQUE_H
